Query Stream
Used to send queries to an AI agent and receive streaming responses. This endpoint allows you to interact with an AI agent's chat history for a specific project and receive real-time responses in a streaming format.
API Endpoint
| Property | Value |
|---|---|
| Request Method | POST |
| Request URL | https://api.seliseblocks.com/ai-agent/query/stream |
Request
Request Example
curl -X POST 'https://api.seliseblocks.com/ai-agent/query/stream' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"query": "What are the features of this product?",
"session_id": "session_123456",
"base_prompt": "You are a helpful customer support assistant",
"model_id": "gpt-4",
"model_name": "GPT-4",
"model_provider": "openai",
"tool_ids": ["tool_1", "tool_2"],
"last_n_turn": 5,
"enable_summary": false,
"enable_next_suggestion": false,
"response_type": "text",
"response_format": "markdown",
"call_from": "project_slug_123",
"files": ["file_id_1"],
"images": ["image_url_1"]
}'
Request Headers
| Field | Type | Required | Description |
|---|---|---|---|
| accept | string | Yes | Accepted response format. Use application/json |
| Content-Type | application/json | Yes | Data type, must be application/json. |
Request Body
Request Body Schema
{
"query": "string",
"session_id": "string",
"base_prompt": "string",
"model_id": "string",
"model_name": "string",
"model_provider": "string",
"tool_ids": ["string"],
"last_n_turn": 5,
"enable_summary": false,
"enable_next_suggestion": false,
"response_type": "text",
"response_format": "string",
"call_from": "string",
"files": ["string"],
"images": ["string"]
}
Request Body Parameters
| Field | Type | Required | Description |
|---|---|---|---|
| query | string | Yes | The user's query or message to send to the AI agent. |
| session_id | string | No | Unique identifier for the chat session. Used to maintain conversation context. |
| base_prompt | string | No | System prompt or base instruction for the AI agent to follow. |
| model_id | string | No | Identifier of the language model to use. |
| model_name | string | No | Human-readable name of the model (e.g., GPT-4, Claude). |
| model_provider | string | No | Provider of the model (e.g., openai, anthropic). |
| tool_ids | array | No | Array of tool identifiers that the agent can utilize to answer the query. |
| last_n_turn | integer | No | Number of previous conversation turns to include as context. Default: 5. |
| enable_summary | boolean | No | Whether to enable automatic summarization of the conversation. Default: false. |
| enable_next_suggestion | boolean | No | Whether to enable suggestions for follow-up queries. Default: false. |
| response_type | string | No | Format of the response (e.g., text, json). Default: text. |
| response_format | string | No | Specific formatting instructions for the response (e.g., markdown, html). |
| call_from | string | No | Project slug identifier to specify which project's AI agent to query. Required to retrieve project-specific chat history. |
| files | array | No | Array of file identifiers to include as context for the query. |
| images | array | No | Array of image URLs to include as context for the query. |
note
- The
call_fromparameter is used to identify which project's AI agent should handle the query and retrieve the corresponding chat history. - The
session_idhelps maintain conversation continuity across multiple queries. - The
last_n_turnparameter controls how much previous conversation context is provided to the model.
Response
Success Response (200 OK)
Returns a streaming text response containing the AI agent's reply.
"The product includes the following features: 1. Real-time chat capabilities, 2. Integration with multiple AI models, 3. Session management, 4. Context-aware responses, and 5. Support for file and image attachments. Would you like more details on any specific feature?"
Response Description
| Field | Type | Description |
|---|---|---|
| (stream) | string | The response is streamed as text. The AI agent's reply to the query, which may include contextual information from the chat history and available tools. The stream continues until the complete response is transmitted. |
info
The response is returned as a stream. This means the data is sent incrementally as it's generated, allowing for real-time display of the AI agent's response.
Error Response
422 Validation Error
Returned when the request body contains invalid or missing required fields.
{
"detail": [
{
"loc": ["query"],
"msg": "Field required",
"type": "missing",
"input": null,
"ctx": {}
}
]
}
Error Fields
| Field | Type | Description |
|---|---|---|
| detail | array | Array of validation error objects. |
| loc | array | Location of the error (field name). |
| msg | string | Human-readable error message. |
| type | string | Type of validation error. |
| input | any | The input value that caused the error. |
Use Cases
- Customer Support: Send customer inquiries and retrieve AI-generated responses from a support agent.
- Knowledge Base Queries: Query an AI agent to retrieve information from project-specific knowledge bases.
- Multi-turn Conversations: Maintain context across multiple queries using the
session_id. - Tool Integration: Leverage AI agent tools to provide enhanced responses with relevant data.
- File & Image Analysis: Include files and images as context for more accurate and detailed responses.
Example Use Case
Retrieving chat history for a project's AI agent:
curl -X POST 'https://api.seliseblocks.com/ai-agent/query/stream' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"query": "Show me the order history for customer ABC123",
"session_id": "session_user_001",
"call_from": "ecommerce_project",
"model_name": "GPT-4",
"model_provider": "openai",
"tool_ids": ["order_database_tool", "customer_lookup_tool"],
"last_n_turn": 10,
"enable_summary": true
}'
This request sends a query to the AI agent associated with the ecommerce_project, utilizing tools to fetch order data and maintain context of the last 10 conversation turns.